package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsMpSlideshowParam;
import com.macro.mall.dto.BmsPromotionalImgParam;
import com.macro.mall.model.BmsMpSlideshow;
import com.macro.mall.model.BmsPromotionalImg;
import com.macro.mall.service.BmsMpSlideshowService;
import com.macro.mall.service.BmsPromotionalImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图管理Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsMpSlideshowController")
@Tag(name = "BmsMpSlideshowController", description = "轮播图管理")
@RequestMapping("/mpSlidesshow")
public class BmsMpSlideshowController {
    @Autowired
    private BmsMpSlideshowService bmsMpSlideshowService;

    @ApiOperation("添加轮播图")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsMpSlideshowParam bmsMpSlideshowParam) {
        int count = bmsMpSlideshowService.create(bmsMpSlideshowParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改轮播图")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsMpSlideshowParam bmsMpSlideshowParam) {
        int count = bmsMpSlideshowService.update(bmsMpSlideshowParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("分页查询轮播图")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<BmsMpSlideshow>> getList(@RequestParam(value = "pageSize") Integer pageSize,
                                                            @RequestParam(value = "pageNum") Integer pageNum) {
        List<BmsMpSlideshow> bmsMpSlideshowList = bmsMpSlideshowService.getList(pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(bmsMpSlideshowList));
    }

    @ApiOperation("根据id获取轮播图信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsMpSlideshow> getItem(@PathVariable Long id) {
        BmsMpSlideshow bmsMpSlideshow = bmsMpSlideshowService.getItem(id);
        return CommonResult.success(bmsMpSlideshow);
    }

    @ApiOperation("删除轮播图")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsMpSlideshowService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改显示状态")
    @RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> updateShowStatus(@RequestBody BmsMpSlideshowParam bmsMpSlideshowParam) {
        int count = bmsMpSlideshowService.updateShowStatus(bmsMpSlideshowParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }



    @ApiOperation("小程序查询轮播图")
    @RequestMapping(value = "/mp/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<BmsMpSlideshow>> getMpList() {
        List<BmsMpSlideshow> bmsMpSlideshowList = bmsMpSlideshowService.getMpList();
        return CommonResult.success(CommonPage.restPage(bmsMpSlideshowList));
    }
}
